package Teilung;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;

public class Server extends JFrame implements ActionListener {

	private Font f1 = new Font("Tahoma",Font.BOLD, 22);
	private Font f2 = new Font("Verdana", Font.ITALIC, 12);
	private Font f3 = new Font("Arial", Font.PLAIN, 12);

	private JButton buttonZeichnen;
	private boolean jButtoneFunktionIsSelected;
	private boolean jButtonLogarithmusIsSelected;
	private boolean jButtonSinusIsSelected;
	private JButton buttonBeenden;
	private JPanel panel;
	private JButton btn_e;
	private JButton btn_Logarithmus;
	private JButton btn_sinus;


	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {	
			public void run() {		
				Server inst = new Server();		
				inst.setLocationRelativeTo(null);		
				inst.setVisible(true);	    }	});

	}
	public Server() {	super();	
	setTitle("e-, Logarithmus-, Sinus-Funktion");initGUI();    }
	private void initGUI() {		
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);	 	
		setSize(1400, 800);		
		getContentPane().setBackground(Color.LIGHT_GRAY);	 	
		getContentPane().setLayout(null);    
		{


		}

		this.panel = new JPanel();
		this.panel.setBounds(10, 729, 555, 33);
		getContentPane().add(this.panel);

		this.btn_e = new JButton("e-Funktion");
		this.btn_e.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btn_e_actionPerformed(e);
			}
		});
		this.btn_e.setToolTipText("Zeichnet die e-Funktion in den Graphen");
		this.panel.add(this.btn_e);

		this.btn_Logarithmus = new JButton("Logarithmus-Funktion");
		this.btn_Logarithmus.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btn_Logarithmus_actionPerformed(e);
			}
		});
		this.btn_Logarithmus.setToolTipText("Zeichnet die Logarithmus-Funktion in den Graphen");
		this.panel.add(this.btn_Logarithmus);

		this.btn_sinus = new JButton("Sinus-Funktion");
		this.btn_sinus.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btn_sinus_actionPerformed(e);
			}
		});
		this.btn_sinus.setToolTipText("Zeichnet die Sinus-Funktion in den Graphen");
		this.panel.add(this.btn_sinus);
		{
			buttonBeenden = new JButton("Programm beenden");
			this.buttonBeenden.setToolTipText("Schlie\u00DFt die Anwendung");
			this.panel.add(this.buttonBeenden);
			buttonBeenden.addActionListener(this);
			buttonBeenden.setMnemonic('b');
		}
	}
	public void paint(Graphics stift) {



		super.paintComponents(stift);		



		int xSize = this.getWidth();
		int ySize = this.getHeight();

		stift.setColor(Color.BLACK);	
		stift.setFont(f1);	
		stift.drawString("Ermittelte Nullstellen", 10, 50);		

		stift.setColor(Color.black);	
		stift.drawLine(0, 400, 1400, 400); 
		stift.drawLine(700, 0, 700, 800);    
		stift.setFont(f2);	stift.drawString("x", xSize-20, ySize/2-10); 

		for (int i = -9; i<=9; i++)	{		
			String str = String.valueOf(i);		
			stift.drawString("|" + str, xSize/2 + i*75, ySize/2+10);	
		}		
		stift.drawString("y", xSize/2-10, 40); 	
		for (int i = 4; i>=-4; i--)	{		
			stift.drawString("-" + i, xSize/2, ((-i*75) +  ySize/2+10));	
		}

		if (jButtoneFunktionIsSelected == true) {

			for (double x =-9; x<=9; x= x+0.001){
				double y = Math.exp(x);
				stift.drawString(" .", xSize/2+(int) (x*75), ySize/2-(int)(y*75));
			}
		}

		if (jButtonLogarithmusIsSelected == true) {

			for (double x =0; x<=9; x= x+0.001){
				double y = Math.log(x);
				stift.drawString(" .", xSize/2+(int) (x*75), ySize/2-(int)(y*75));
			}
		}

		if (jButtonSinusIsSelected == true) {

			for (double x = -9; x<=9; x= x+0.001){
				double y = Math.sin(x);
				stift.drawString(" .", xSize/2+(int) (x*75), ySize/2-(int)(y*75));
				
			}
		}
	}

	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == buttonBeenden) {
			buttonBeendenActionPerformed(arg0);
		}
	}

	protected void buttonBeendenActionPerformed(ActionEvent arg0) {
		System.exit(0);
	}

	protected void do_btn_e_actionPerformed(ActionEvent e) {
		jButtoneFunktionIsSelected = true;      
		this.repaint();
	}

	protected void do_btn_Logarithmus_actionPerformed(ActionEvent e) {
		jButtonLogarithmusIsSelected = true;      
		this.repaint();
	}

	protected void do_btn_sinus_actionPerformed(ActionEvent e) {
		jButtonSinusIsSelected = true;      
		this.repaint();
	}
}
